﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TsCore;
using System.Globalization;

namespace TsWeb.Reports
{
    public partial class UserLogonReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                fromDateText.Text = DateTime.Now.ToShortDateString();
                toDateText.Text = DateTime.Now.AddMonths(1).ToShortDateString();
                msgLabel.Text = "Realice una búsqueda por favor";
                msgLabel.Visible = true;
            }

        }


        protected void ButtonSearchLogs_Click(object sender, EventArgs e)
        {
            
            DateTime dateFrom = DateTime.Now;
            if (fromDateText.Text != "")
            {
                dateFrom = Convert.ToDateTime(fromDateText.Text, CultureInfo.CurrentCulture);

            }
            DateTime dateTo = DateTime.Now;
            if (toDateText.Text != "")
            {
                dateTo = Convert.ToDateTime(toDateText.Text, CultureInfo.CurrentCulture);

            }
            List<AuditLogEntity> logs = TsSystem.Instance.GetUserLogons(dateFrom, dateTo);
            GridViewLogs.DataSource = logs;
            GridViewLogs.DataBind();
            GridViewLogs.UseAccessibleHeader = true;
            if (GridViewLogs.HeaderRow != null)
            {
                GridViewLogs.HeaderRow.TableSection = TableRowSection.TableHeader;
            }
            msgLabel.Visible = false;
            if (logs.Count == 0)
            {
                msgLabel.Text = "No hay se encontraron datos";
                msgLabel.Visible = true;
            }
            

        }


    }
}